

using System.Collections;
using MyFrame.Mono;
using Platform.Skill.Core;
using Platform.Skill.Deployer;
using UnityEngine;
using Plugin.Tool;
using static Entity;

namespace GardeningSkeleton.Platform.SkillSpace
{
    public class CloneImpact : BaseImpactEffect
    {
        private CloneSkillDeployer deployer;
        private Coroutine attackCor;

        public override void EndEffect()
        {
            MonoMgr.Instance.StopCoroutine(attackCor);
        }

        public override void Execute(SkillDeployer deployer)
        {
            skillData = deployer.SkillData;

            this.deployer = (CloneSkillDeployer)deployer;

            attackCor = MonoMgr.Instance.StartCoroutine(Attack());
        }
        /// <summary>
        /// 带有延时的攻击
        /// </summary>
        /// <returns></returns>
        IEnumerator Attack()
        {
            while (true)
            {
                this.deployer.anim.SetBool("LightDoubleAttack", true);
                this.deployer.anim.SetInteger("LightDoubleCombo", Random.Range(1, 3));

                // 获取真实动画长度
                yield return new WaitForSeconds(0.01f);
                AnimatorStateInfo stateInfo = this.deployer.anim.GetCurrentAnimatorStateInfo(0);
                yield return new WaitForSeconds(stateInfo.length); // 等待动画播放完成
                this.deployer.anim.SetBool("LightDoubleAttack", false);
                this.deployer.anim.SetBool("Idle", true);
                yield return new WaitForSeconds(skillData.attackInterval); // 暂停
            }
        }

        public override void OnImpactTriggerEntry(Collider2D other)
        {

        }
    }
}